package aiproject3.util;

import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;

public class FileParser {

    private String fname;
    
    public FileParser(String fname) {
        this.fname = fname;
    }
    
    public void parseFile(String outName) {
        File oFile = new File(outName);
        File iFile = new File(fname);
        System.out.println("Current dir: " + System.getProperty("user.dir"));
        if (!oFile.exists()) {
            try {
                int tmp;
                FileWriter fw = new FileWriter(oFile);
                FileReader fr = new FileReader(iFile);
                
                while((tmp = fr.read()) != -1) {
                    
                    if(!Character.isLetter(tmp)) continue;
                    
                    if(tmp > 'Z') tmp = (char)(tmp - 'a' + 'A');
                    fw.write(tmp);
                    fw.write(',');     
                    System.out.print(tmp + ",");
                }
                System.out.println();
                fw.close();
                fr.close();
            } catch (IOException ex) {
                System.out.println("Error: Unable to create new test file... \n" + ex.getMessage());
            }
            
        }
    }
    
    public void setInputName(String fname) {
        this.fname = fname;
    }
}
